package yxy.game.pm2.active.module.lockorder;

import yxy.apple.util.redisson.RedisException;
import yxy.game.pm2.bean.module.BaseGameRedisBean;

/**
 * 锁单参数
 * @author Dell
 *
 */
public class LockOrderInfo extends BaseGameRedisBean {

	//bean -------------------------------------------------
	private int locktime;	//锁单时间 单位秒

	public int getLocktime() {
		return locktime;
	}

	public void setLocktime(int locktime) {
		this.locktime = locktime;
	}

	//func --------------------------------------------------
	private static final int mrltime = 5;	//默认锁单时间 5秒

	public static int lockTime() {
		LockOrderInfo info = get();
		if(info == null) {
			return mrltime;
		}
		return info.getLocktime();
	}
	
	private static LockOrderInfo create() {
		LockOrderInfo lockinfo = new LockOrderInfo();
		lockinfo.setLocktime(mrltime);
		lockinfo.set();
		return lockinfo;
	}
	
	public void update() {
			
	}
	
	//redis --------------------------------------------------
	
	static private String key() {
		return "LOCKORDER:INFO";
	}

	public void set() {
		try {
			setv(key(), this);
		} catch (RedisException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取 LockOrderInfo
	 * @return
	 */
	static public LockOrderInfo get() {
		try {

			LockOrderInfo module = getv(key());
			if (module == null) {
				module = create();
			}

			return module;
		} catch (RedisException e) {
			e.printStackTrace();
		}
		return null;
	}

	// lock==========================================================================

	@Override
	public String lockKey() {
		return String.format("lock:%s", key());
	}
	
}
